import { createApp } from 'vue'
import './style.css'
import App from './App.vue'

import { loading } from '@/utils/customInstructions'

import '@/style/pubilcStyle.css'

import '@/style/index.scss'

import 'virtual:windi.css'

import ElementPlus from 'element-plus'

import router from './router'

import '@/mock/index'

// import svgIcon from '@/components/svgIcon.vue'
import 'virtual:svg-icons-register'

import Print from 'vue3-print-nb'

import * as ElementPlusIconsVue from '@element-plus/icons-vue'

import '@/assets/fonts/icons/iconfont.css'
import '@/assets/fonts/js/iconfont.js'

import '@/assets/fonts/font.css'

// import esEcharts from '@/components/esEcharts.vue'

// 统一引入组件
const components = import.meta.glob('./components/**/*.vue', {
  import: 'default', // default表示只导入每个匹配文件的默认导出（组件本身）
  eager: true, // true表示启动是立即执行导入操作，而不是懒加载
})

import '@/permission.ts'

import pinia from './stores/index'

import esTable from '@/components/esTable.tsx'

import Particles from "@tsparticles/vue3";
// import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
import { loadSlim } from "@tsparticles/slim"; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.


const app = createApp(App)

app.directive('load', loading)

app.use(ElementPlus)

app.use(router)

// app.component('svgIcon', svgIcon)

app.use(Print)

// app.component('es-echarts', esEcharts)

// 统一注册组件
Object.keys(components).forEach((key) => {
  // 遍历 components 对象，注册全局组件
  const componentName = key
    .split('/')
    .pop()
    .replace(/\.vue$/, '') // 提取组件名称
  console.log(componentName, components[key], '注册组件')

  app.component(componentName, components[key]) // 注册组件
})

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

app.use(pinia)

app.component('esTable', esTable)

//使用Particles
app.use(Particles, {
  init: async engine => {
   // await loadFull(engine); // you can load the full tsParticles library from "tsparticles" if you need it
    await loadSlim(engine); // or you can load the slim version from "@tsparticles/slim" if don't need Shapes or Animations
  },
})


// 挂载应用
app.mount('#app')
